package operation;


import abbot.finder.Matcher;
import abbot.finder.matchers.NameMatcher;
import robotCross.TipMatcher;
import socketEnv.CrossProperties;

import javax.swing.*;

/**
 * Created by caolp on 2016-11-09.
 */
public class ImportDataOperation extends Operation {
	//在打开的数据导入对话框中添加文件
	public void addImportFile(Matcher addFileMatcher, String filePath) throws Exception {
		new DialogOperation().clickComponent(addFileMatcher);
		//代码执行过程汇总打开过\\192.168.15.249上的文件，文件选择器会保留这个路径，
		// 下一次打开文件选择器的时候，共享路径可能ping不同，文件选择器初始化的时候会使用很长的时间判断共享路径是否存在，
		//导致JFileChooser显示需要很久，硬编码很长的等待时间太浪费，故而用等待显示。
		JFileChooser jFileChooser = new CommonOperation().waitForJFileChooserDisplay();
		new JFileChooserOperation(jFileChooser).chooseFile(filePath);
	}

	public void addImportFile(String filePath) throws Exception {
		this.addImportFile(new NameMatcher("DataImportDialog_buttonAddFile"), filePath);
	}

	public void addImportFiles(String[] filePaths) throws Exception {
		new DialogOperation().clickComponent(new TipMatcher(CrossProperties.getProperty(CrossProperties.PropertiesEnum.DataConversion, "String_button_addFile")));
		JFileChooser jFileChooser = new CommonOperation().waitForJFileChooserDisplay();
		new JFileChooserOperation(jFileChooser).chooseFiles(filePaths,true);
	}

	public void addImportFiles(String filesDir, String[] fileNames) throws Exception {
		new DialogOperation().clickComponent(new NameMatcher("DataImportDialog_buttonAddFile"));
		JFileChooser jFileChooser = new CommonOperation().waitForJFileChooserDisplay();
		new JFileChooserOperation(jFileChooser).chooseFiles(filesDir,fileNames,true);
	}
}
